import Mock from 'mockjs'
//首先引入mockjs模块

// 定义一个数组来存放生成的每个data对象
const arr = []
for (let i = 0; i < 5; i++) {
  const data = Mock.mock({
    id: i + 1,
    isSelected: false,
    //下面是通过mckjs模块产生随机数据
    productPic: `https://www.robohash.org/${i + 1}`,
    productName: Mock.Random.cparagraph(1),
    productInfo: Mock.Random.cparagraph(1),
    price: Mock.Random.float(0, 100), //
    number: 1,
  })
  arr.push(data)
}

// console.log(arr, 'arr')
// 模拟数据
// 购物车列表接口
Mock.mock('/api/list', function () {
  return {
    code: 0,
    msg: 'success',
    data: arr,
  }
})

// 模拟接口
Mock.mock('/api/users', function () {
  return {
    code: 0,
  }
})

Mock.mock('/api/login', 'post', function ({ body }) {
  console.log(JSON.parse(body), 'body')
  return {
    code: 0,
  }
})
